package com.frxuexi.visit

import com.frxuexi.lib_base.http.ApiService
import com.frxuexi.lib_base.mvi.BaseViewModel
import com.frxuexi.lib_base.mvi.RequestType
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

@HiltViewModel
class VisitViewModel @Inject constructor(val apiService: ApiService) :
    BaseViewModel<VisitIntent>() {
    override fun handlerIntent(it: VisitIntent) {
        when (it) {
            is VisitIntent.getVisits -> {
                httpRequest(apiService.getVisits())
            }

            is VisitIntent.getVisitByStatus -> httpRequest(apiService.getVisitByStatus(it.status))
            is VisitIntent.getVisitByName -> httpRequest(apiService.getVisitByName(it.name))
            is VisitIntent.getVisitByPurpose -> httpRequest(apiService.getVisitByPurpose(it.purpose))
            is VisitIntent.addVisit -> httpRequest(apiService.addVisit(toBody(it.beanItem)))
            is VisitIntent.deleteVisit -> httpRequest(apiService.deleteVisit(it.id),RequestType.DELETE)
            is VisitIntent.getVisitById->httpRequest(apiService.getVisitById(it.id))
            is VisitIntent.approveVisit->httpRequest(apiService.approveVisit(it.id),RequestType.UPDATE)
            is VisitIntent.rejectVisit->httpRequest(apiService.rejectVisit(it.id),RequestType.UPDATE)
            else -> {}
        }
    }
}